package frontend.parser.syntaxtree;

import frontend.lexer.TKType;
import frontend.parser.syntaxtree.symbol.NonTerminalSymbol;
import frontend.parser.syntaxtree.symbol.TerminalSymbol;

import java.util.function.Consumer;

/**
 * funcdef 函数参数结点
 *
 * @author 杨凯伟
 * @date 2024/10/14
 */
public class FuncDefNode extends SyntaxNode {
    public FuncTypeNode funcType;
    public String ident;
    public FuncFParamsNode params;
    public BlockNode block;
    public int identLineNum = -1;

    @Override
    public void walk(Consumer<TerminalSymbol> terConsumer, Consumer<NonTerminalSymbol> nonTerConsumer) {
        funcType.walk(terConsumer, nonTerConsumer);

        terConsumer.accept(new TerminalSymbol(TKType.IDENFR, ident));

        terConsumer.accept(new TerminalSymbol(TKType.LPARENT));

        if (params != null) {
            params.walk(terConsumer, nonTerConsumer);
        }

        terConsumer.accept(new TerminalSymbol(TKType.RPARENT));

        block.walk(terConsumer, nonTerConsumer);

        nonTerConsumer.accept(new NonTerminalSymbol(this));
    }

    @Override
    public String getType() {
        return "FuncDef";
    }
}
